def printMonth(year,month):
    printMonthTitle(year,month)
    printMonthBody(year,month)


def printMonthTitle(year,month):
    print("          ",getMonthName(month)," ",year)
    print("-------------------------------------")
    print('SUN  MON  TUE  WED  THU  FRI  SAT')

def printMonthBody(year,month):
    startDay = getStartDay(year,month)
    numberOfDaysInMonth = getNumberOfDaysInMonth(year,month)
    i = 0
    for i in range(0,startDay):
        print("    ",end = "")

    for i in range(1,numberOfDaysInMonth + 1):
        print(format(i,"4d"),end = "")
        if (i+startDay) % 7 == 0:
            print()

def getMonthName(month):
    if month == 1:
        return "一月"
    elif month == 2:
        return "二月"
    elif month == 3:
        return "三月"
    elif month == 4:
        return "四月"
    elif month == 5:
        return "五月"
    elif month == 6:
        return "六月"
    elif month == 7:
        return "七月"
    elif month == 8:
        return "八月"
    elif month == 9:
        return "九月"
    elif month == 10:
        return "十月"
    elif month == 11:
        return "冬月"
    elif month == 12:
        return "腊月"

def getStartDay(year,month):
    START_DAY_FOR_JAN_1_1800 = 3
    totalNumberOfDays = getTotalNumberOfDays(year,month)
    return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800 ) % 7

def getTotalNumberOfDays(year,month):
    total = 0
    for i in range(1800,year):
        if isLeapYear(i):
            total = total + 366;
        else:
            total = total + 365

    for i in range(1,month):
        total = total + getNumberOfDaysInMonth(year,i)
    return total

def getNumberOfDaysInMonth(year,month):
    if (month == 1 or month == 3 or month == 5 or month == 7 or
        month == 8 or month == 10 or month == 12):
        return 31
    if month ==4 or month == 6 or month == 9 or month ==11:
        return 30
    if month == 2:
        return 29 if isLeapYear(year) else 28

    return 0

def isLeapYear(year):
    return year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)

def main():
    year = eval(input("year"))
    month = eval(input("month"))
    printMonth(year,month)

main()

